#include <iostream>
#include <vector>
using namespace std;

const int N = 15;
int n;
bool col[N], st1[N * 2], st2[N * 2];

int ret;
vector<int> path;

void dfs(int x)
{
    if(x > n)
    {
        ret++;
        if(ret <= 3)
        {
            for(auto e : path) cout << e << " ";
            cout << endl;
        }
        return;
    }

    for(int i = 1; i <= n; i++)
    {
        if(col[i] || st1[i - x + n] || st2[i + x])
            continue;

        col[i] = st1[i - x + n] = st2[i + x] = true;
        path.push_back(i);
        dfs(x + 1);
        col[i] = st1[i - x + n] = st2[i + x] = false;
        path.pop_back(); 
    }
}

int main()
{
    cin >> n;
    dfs(1);
    cout << ret << endl; 
    return 0;
}
